package Service;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import com.example.permanentroom.MainActivity;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import Entity.User;
import Entity.commodity;


public class GouwucheService {






	public void pay(ArrayList<Integer> arr, String userid, Context context){
		Gson gson=new Gson();
		String json = gson.toJson(arr);
		try{
			String sql="create table Order_(id INTEGER primary key  autoincrement,commo_id char (15),user_id char (15),type char(30))";
			SQLiteDatabase db=new DatabaseHelper(context).getWritableDatabase();

			db.execSQL(sql);
		for(int in:arr){
			Map<String,String> map=new HashMap();
			map.put("commo_id", String.valueOf(in));
			map.put("user_id", MainActivity.userid);
			map.put("type","1");
			sql="insert into Order_( commo_id, user_id, type) values(?,?,?)";
			Object[] obj ={in,MainActivity.userid,"1"};
			db.execSQL(sql,obj);
		}} catch (SQLException e) {
			e.printStackTrace();
		}


		Map<String,String> map = new HashMap();
		map.put("cmd","pay");
		map.put("list",json);
		map.put("userid",userid+"");
		String userJson = gson.toJson(map);
		new Transfer_station().transfer(userJson);
	}



}
